/**
 *
 */
package com.cmcc.awareness;

import java.util.ArrayList;

/**
 * @Date 2018年4月11日 上午11:20:48
 * @author Amish
 * 抽象为一个业务(应用)小类细分/App Content、保存其对应的所有Rule。
 */
public class HttpProtoApp {
	
	/**
	 *  [QIYI_Browsing]
		#Rule_ID:12504
		name=QIYI_Browsing
		Uri=appid=com.qiyi
		
		[QIYI_Browsing-1]
		#Rule_ID:16126
		name=QIYI_Browsing
		User-Agent=QIYI
		
		[QIYI_Browsing-2]
		#Rule_ID:20699
		Referer=qiyi.com
		name=QIYI_Browsing
		
		[QIYI_Browsing-3]
		#Rule_ID:24487
		Referer=.iqiyi.com
		name=QIYI_Browsing
		Uri=iqiyi
		
		[QIYI_Browsing-4]
		#Rule_ID:24773
		Host=iqiyi.irs01.com
		name=QIYI_Browsing
		
		[QIYI_Browsing-5]
		#Rule_ID:24774
		Host=viqiyi.admaster
		name=QIYI_Browsing
		
		[QIYI_Browsing-6]
		#Rule_ID:5811
		Host=qiyi.com
		name=QIYI_Browsing
		
		[QIYI_Browsing-7]
		#Rule_ID:5880
		Host=.video.qiyi.
		name=QIYI_Browsing
		
		[QIYI_Browsing-8]
		#Rule_ID:7464
		Host=.qiyipic.com
		name=QIYI_Browsing
		
		[QIYI_Browsing-9]
		#Rule_ID:9901
		name=QIYI_Browsing
		Uri=video.qiyi.com
		
		[QIYI_Browsing-10]
		#Rule_ID:9902
		name=QIYI_Browsing
		Uri=.qiyi.com/videos
		
		[QIYI_Browsing-11]
		#Rule_ID:9903
		Host=qiyiv.dnion.com
		name=QIYI_Browsing
		Uri=/videos
		
		[QIYI_Browsing-12]
		#Rule_ID:9905
		Host=qiyi.soooner.com
		name=QIYI_Browsing
		
		[QIYI_Browsing-13]
		#new rule
		Host=msg.71.am
		name=QIYI_Browsing
		
		[QIYI_Browsing-14]
		#new rule
		Uri=ua=UA-iqiyi-
		name=QIYI_Browsing
		
		[QIYI_Browsing-15]
		#new rule
		User-Agent=%E7%88%B1%E5%A5%87%E8%89%BA/
		name=QIYI_Browsing
		
		[QIYI_Browsing-16]
		#new rule
		Uri=/cdn/qiyiapp/
		name=QIYI_Browsing
		
		#new20171103
		[QIYI_Browsing-17]
		Host=iqiyi.com
		name=QIYI_Browsing
		
		[QIYI_Browsing-18]
		Tls_server=.iqiyi.com
		name=QIYI_Browsing
		
		[QIYI_Browsing-19]
		Tls_server=iqiyi.*.com
		name=QIYI_Browsing
	 */
	
	public String appName;//对应proto.list中的业子项名称，如QIYI_Browsing、WeiXin_VoIP_Voice
	
	public ArrayList<HttpProtoRule> rules;
	
	public HttpProtoApp(){
		rules = new ArrayList<HttpProtoRule>();
	}
	
	public String distinguish(org.apache.http.HttpRequest httpRequest){
		
		for(HttpProtoRule httpProtoRule : rules){
			if(httpProtoRule.distinguish(httpRequest)){
				return appName;
			}
		}
		return null;	
	}
	
	
	public String distinguish(String https_Tls_server , String https_id_at_commonName){
		
		for(HttpProtoRule httpProtoRule : rules){
			if(httpProtoRule.distinguish(https_Tls_server , https_id_at_commonName)){
				return appName;
			}
		}
		return null;
	}
	
	public HttpProtoRule distinguishWithRule(org.apache.http.HttpRequest httpRequest){
		
		for(HttpProtoRule httpProtoRule : rules){
			if(httpProtoRule.distinguish(httpRequest)){
				return httpProtoRule;
			}
		}
		return null;	
	}
	
	
	public HttpProtoRule distinguishWithRule(String https_Tls_server , String https_id_at_commonName){
		
		for(HttpProtoRule httpProtoRule : rules){
			if(httpProtoRule.distinguish(https_Tls_server , https_id_at_commonName)){
				return httpProtoRule;
			}
		}
		return null;
	}
	

}
